package com.linkgie.galaxyframework.utils;

import java.util.function.Function;

public class Functions {

	private static final ConstantFunction CONSTANT = new ConstantFunction();

	/**
	 * 保持传入对象不变原样输出的功能；
	 * 
	 * @param <T>
	 * @param <R>
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T, R> Function<T, R> constant() {
		return (Function<T, R>) CONSTANT;
	}

	/**
	 * 保持传入对象不变原样输出；
	 * 
	 * @author huanghaiquan
	 *
	 */
	private static class ConstantFunction implements Function<Object, Object> {

		@Override
		public Object apply(Object t) {
			return t;
		}

	}

}
